const app = getApp()
var CONFIG = require("../../../config/config.js");
var share = require('../../../utils/share.js');

Page({

    /**
     * 页面的初始数据
     */
    data: {
        tel: '',
        id: '', //课程id
        status: -1,
        msg: '',
        nper_jn: [],
        user_id: '',
        course_name: '',
        is_hide_class: 1,
        nper_jno: [],
    },
    classnope() {
        this.setData({
            is_hide_class: 2
        })
    },
    singclick(e) {
        var that = this;
        var id = e.target.dataset.id;
        wx.navigateTo({
            url: '/pages/student/period/addnewsign?id=' + id + '',
        })
    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this;
        wx.showLoading({
            title: '加载中~',
            mask: true
        })

        if (options.stu_id) {
            this.setData({
                id: options.stu_id,
                user_id: options.user_id,
                course_name: options.course_name
            });
        }


        // 获取本地手机号
        var phone = wx.getStorageSync('tel');
        that.setData({
            tel: phone
        })
        that.queryNper(that.data.id, that.data.tel);
    },

    /**
     * 查询报课信息
     */
    queryNper: function(id, tel) {
        var that = this;
        var data = {
            course_id: id,
            user_id: that.data.user_id
        }
        share.wxRequest('crmapi/Classroom/queryClassStu', data, function(res) {
            that.setData({
                status: res.data.errcode,
                msg: res.data.msg
            })
            if (Number(res.data.errcode) == 0) {
                var data = res.data.data;
                var nper_jn1 = [],
                    nper_jn2 = [];
                // "is_report": 1,// 状态:1-未报到2-已报到3-不来4-已退费 
                for (var i = 0; i < data.length; i++) {
                    if (Number(data[i].is_report) == 3 || Number(data[i].is_report) == 4) {
                        nper_jn2.push(data[i])
                    } else {
                        nper_jn1.push(data[i])
                    }
                }
                that.setData({
                    nper_jn: nper_jn1,
                    nper_jno: nper_jn2,
                })
            }
            wx.hideLoading();
        })
    },


    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})